<template>
  <a-table
    :columns="columns"
    :data-source="tableList"
    :pagination="pagination"
    :scroll="{ y: '780px' }"
    @change="handleChangePage"
  >
    <template #bodyCell="{ record, column }">
      <template v-if="column.dataIndex === 'updateBy'">
        {{ dayjs(record.updateBy).format('YYYY-MM-DD HH:mm:ss') }}
      </template>
      <template v-if="column.dataIndex === 'status'">
        <a-switch v-model:checked="record.status" :checkedValue="'1'" :unCheckedValue="'0'" />
      </template>
      <template v-if="column.dataIndex === 'cover'">
        <img v-if="record.cover" :src="cloudId2Http(record.cover)" alt="" class="cover-img" />
      </template>
    </template>
  </a-table>
</template>
<script lang="ts" setup>
import dayjs from 'dayjs'
import { cloudId2Http } from '@/utils/wechat-cloud-url'
import type { TTable } from './type.dict'
const emit = defineEmits(['changePagination'])

defineProps<{
  tableList: TTable[]
  pagination: {
    total: number
    current: number
    pageSize: number
  }
}>()
const handleChangePage = (e: { current: number; pageSize: number }) => {
  emit('changePagination', {
    pageSize: e.pageSize,
    current: e.current,
  })
}
const columns = [
  {
    title: '昵称',
    dataIndex: 'nickname',
    width: 100,
  },
  {
    title: '头像',
    dataIndex: 'cover',
    width: 140,
  },
  {
    title: '总积分',
    dataIndex: 'all_points',
    width: 100,
  },
  {
    title: '已用积分',
    dataIndex: 'use_points',
    width: 100,
  },
  {
    title: 'openid',
    dataIndex: 'openid',
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'updateBy',
  },
]
</script>
<style lang="stylus" scoped>
@import "@/assets/antgloab-ant.css";

.active {
  color: #1677ff;
}
.red{
  color red
}
.cover-img {
  width: 100px;
  height: 100px;
  object-fit: cover;
}
.modal-center {
  display flex
  flex-direction column
  align-items center
  justify-content center
  margin 46px 0 40px

  .modal-text {
    margin 16px 0 56px
    font-size 16px
    font-weight 500
  }

  .modal-btn {
    width 200px
    height 46px
    border-radius: 4px
    background #3483FF
    font-weight 500
    font-size 16px
  }
}

:deep(.ant-table-body::-webkit-scrollbar) {
  width: 0;
}

.header_text {
  color: rgba(0, 0, 0, 0.88);
  font-weight: 600;
}
</style>
